function check_add_hdcp(id_row,add,tien_sua,idsua,dachi,dinhdang){
	sotien=document.getElementById('sotienchi_'+id_row);
	sotien_=document.getElementById('sotienchi_'+id_row+'_');
	start = document.getElementById('ngaychi_'+id_row);
	end = document.getElementById('ngaychi_tt_'+id_row);
	var view = COREJS._getJsLang('view');
	var Hdo_Id = COREJS._getJsLang('Hdo_Id');
	if(sotien_.value==''){
		alert(COREJS._getJsLang('_BAN_CHUA_NHAP_SO_TIEN_CHI'));
		sotien.focus();
		return false;
	}
	if(sotien_.value<=0){
		alert(COREJS._getJsLang('_SO_TIEN_CHI_PHAI_DUONG'));
		sotien.focus();
		return false;
	}
	if(COREJS._getJsLang('DINH_DANG') == 1){
		var dinhdang = '/';
	}
	else if(COREJS._getJsLang('DINH_DANG') == 2){
		var dinhdang = '-';
	}
	else{
		var dinhdang = '.';
	}
	if(end.value!=""){
		Ngay_Bat_Dau= (start.value).split(dinhdang);
		ngay_bd=Ngay_Bat_Dau[0];
		thang_bd=Ngay_Bat_Dau[1];
		nam_bd=Ngay_Bat_Dau[2];
		Ngay_KT= (end.value).split(dinhdang);
		ngay_kt=Ngay_KT[0];
		thang_kt=Ngay_KT[1];
		nam_kt=Ngay_KT[2];
		if(nam_bd*1 > nam_kt*1){
			alert(COREJS._getJsLang('_ALERT_NGAY_CHI_TT_LONHON_NGAY_CHI'));
			end.focus();
			return false;
		}
		if(nam_bd*1 == nam_kt*1){
			if(thang_bd*1 > thang_kt*1){
				alert(COREJS._getJsLang('_ALERT_NGAY_CHI_TT_LONHON_NGAY_CHI'));
				end.focus();
				return false;
			}
			if(thang_bd*1 == thang_kt*1){
				if(ngay_bd*1 > ngay_kt*1){
					alert(COREJS._getJsLang('_ALERT_NGAY_CHI_TT_LONHON_NGAY_CHI'));
					end.focus();
					return false;
				}
			}
		}
	}
	if(document.getElementById('Da_Chi_'+id_row).checked==true && end.value==""){
		alert(COREJS._getJsLang('_BAN_CHUA_CHON_NGAY_CHI_THUC_TE'));
		end.focus();
		return false;
	}
	else{
		var tongchiphi=document.getElementById('tongchiphi_').value;
		if(document.getElementById('Da_Chi_'+id_row).checked==true){
			var co_check=1;
		}
		else{
			var co_check=0;
		}
		if(dachi=='add'){
			if(co_check==1){
				//tinh them tien
				var tien_da_chi=tongchiphi*1+sotien_.value*1-tien_sua*1;
			}
			else{
				//tinh them tien
				var tien_da_chi=tongchiphi;
			}
		}
		else{
			//truong hop check da c va suhia van check
			if(co_check==1 && dachi==1){
				//tinh them tien
				var tien_da_chi=tongchiphi*1+sotien_.value*1-tien_sua*1;
			}
			//truong hop check thanh toan nhung truoc ko check
			if(co_check==1 && dachi==0){
				//tinh them tien
				var tien_da_chi=tongchiphi*1+sotien_.value*1;
			}
			//truong hop h khong check nhung truoc co check
			if(co_check==0 && dachi==1){
				var tien_da_chi=tongchiphi*1-tien_sua*1;
			}
			if(co_check==0 && dachi==0){
				var tien_da_chi=tongchiphi;
			}
		}
		if(view == 1){
			document.getElementById('tongchiphi').innerHTML=formatNumber_DB(tien_da_chi);
		}
		else{
			document.getElementById('tongchiphi').value=formatNumber_DB(tien_da_chi);
		}
		document.getElementById('tongchiphi_').value = tien_da_chi;
		//count hop dong chi
		
		if(id_row!=0){
			//add hop dong chi phi
			var getFormValues = $('#frm_popup_hdcp_'+id_row).serialize();
			var urlaction = "modules/contract/AddHdcp.php?id_row="+id_row+'&'+getFormValues+'&add='+add+'&tien_da_chi='+tien_da_chi+'&hdc_id='+idsua;
			$.getJSON(urlaction,null,function(data){
				document.getElementById('row_suahdcp_'+id_row).innerHTML = data;
			});
			$('.dialogChiPhi_'+id_row).dialog('close');
			jQuery("#dialogChiPhi_"+id_row).remove();
			
		}
		else{
			var getFormValues = $('#frmAddHdcp').serialize();
			var urlaction = "modules/contract/AddHdcp.php?id_row="+id_row+'&'+getFormValues+'&add='+add+'&tien_da_chi='+tien_da_chi+'&hdc_id='+idsua;
			$.getJSON(urlaction,null,function(data){
				$(data).appendTo("#divrowhopdongchiphi");
			});
			$("#dialogAddHDCP").dialog("close");
			//reset 
			document.getElementById('sotienchi_0_').value='';
			document.getElementById('sotienchi_0').value='';
			document.getElementById('gc_chi_0').value='';
			document.getElementById('ngaychi_tt_0').value='';
		}
		document.getElementById('hopdongcp').style.display='none';
	}
}
function check_unckeck(id,date){
	if(document.getElementById('Da_Chi_'+id).checked==true){
		document.getElementById('ngaychi_tt_'+id).value=date;
	}
	else{
		document.getElementById('ngaychi_tt_'+id).value='';
	}
}

function delete_hdcp(id_row,id,tien_xoa,dachi){
	so_hdcp_ht=document.getElementById('count_hdcp').value;
	jQuery("#row_suahdcp_"+id_row).remove();
	count_hdcp = so_hdcp_ht*1-1;
	document.getElementById('count_hdcp').value=so_hdcp_ht*1-1;
	document.getElementById('display_count_hdcp').innerHTML=so_hdcp_ht*1-1;
	tien_da_chi=document.getElementById('tongchiphi_').value;
	var view = COREJS._getJsLang('view');
	if(dachi==1){
		//tien chua thanh toan
		tien_da_chi=tien_da_chi*1-tien_xoa*1;
	}
	if(view == 1){
		document.getElementById('tongchiphi').innerHTML=formatNumber_DB(tien_da_chi);
	}
	else{
		document.getElementById('tongchiphi').value=formatNumber_DB(tien_da_chi);
	}
	
	document.getElementById('tongchiphi_').value=tien_da_chi;
	if(id!=''){
		id_table=document.getElementById('id_table').value;
		var urlaction = COREJS._getJsLang('URL')+"/modules/hopdong/edit/deleteHDCP?id="+id+'&id_table='+id_table+'&tien_da_chi='+tien_da_chi;
			$.getJSON(urlaction,null,function(data){
			});
	}
	if(count_hdcp == 0){
		document.getElementById('hopdongcp').style.display='block';
	}
}